import java.util.Arrays;

public class Leetcode2309 {
    public static void main(String[] args) {
        System.out.println(greatestLetter1("lEeTcOdE"));
        System.out.println(greatestLetter1("arRAzFif"));
        System.out.println(greatestLetter1("AbCdEfGhIjK"));
    }

    public static String greatestLetter(String s) {
        boolean[] capitalFlag = new boolean[26];
        boolean[] lowercaseFlag = new boolean[26];

        char res = 0;
        for (char c : s.toCharArray()) {
            if (c >= 'a' && c <= 'z') {
                lowercaseFlag[c - 'a'] = true;
                if (capitalFlag[c - 32 - 'A'] && c - 32 > res) {
                    res = (char) (c - 32);
                }
            } else {
                capitalFlag[c - 'A'] = true;
                if (lowercaseFlag[c + 32-'a'] && c > res) {
                    res = c;
                }
            }
        }

        return res == 0 ? "" : String.valueOf(res);
    }

    public static String greatestLetter1(String s) {
        System.out.println(Arrays.toString(s.chars().map(m->m&31).toArray()));
        return "";
    }
}
